//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Components;
using CommunityServer.Components;
using CommunityServer.Controls;

namespace CommunityServer.Blogs.Controls
{
	/// <summary>
	/// Summary description for AboutView.
	/// </summary>
	public class DownloadAttachmentLink : WeblogThemedControl
	{
		public DownloadAttachmentLink()
		{
			//
			// TODO: Add constructor logic here
			//
		}

        protected HyperLink downloadLink;
        private PostAttachmentMetaData _data = null;


        protected override void AttachChildControls()
        {
            downloadLink = FindControl("DownLoadLink") as HyperLink;
        }
        
        public PostAttachmentMetaData DataSource
        {
            get{return _data;}
            set{_data = value;}
        }

        public override void DataBind()
        {
            base.DataBind ();

            if(DataSource != null && downloadLink != null)
            {
                downloadLink.NavigateUrl = BlogUrls.Instance().AttachmentUrl(this.CurrentWeblog,  DataSource);
                downloadLink.Text = DataSource.FileName;
                if(DataSource.IsRemote)
                    downloadLink.Target = "_blank";
            }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender (e);
            if(DataSource == null || downloadLink == null)
                this.Visible = false;
        }


	}
}
